﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApp2
{
    public partial class Form1 : Form
    {
        int ID = 0;
        int i = 0;
        //闪烁图标
        private Icon ico1 = Properties.Resources.Icon1;
        //常亮图标
        private Icon ico2 = Properties.Resources.icon15;

        public Form1()
        {
            InitializeComponent();  
        }

        private void Form1_Load(object sender, EventArgs e)
        {  
            this.Visible = false;
            notifyIcon1.Visible = true;
            //启动timer2 查询数据库是否有新的打印申请
            this.timer2.Start();
        }
       
        private void timer1_Tick(object sender, EventArgs e)
        { 
            //timer1 图标闪烁定时器
            if (i < 1)
            {
                this.notifyIcon1.Icon = ico2;
                i++;
                return;
            }
            else
            {
                this.notifyIcon1.Icon = ico1;
                i = 0;
            }
        }

       

        private void timer2_Tick(object sender, EventArgs e)
        {   //timer2 数据库查询定时器
            //查询数据库是否有打印申请定时器 1 为正在申请
            string sql = "select * from T_CARDINFO where CARD_PRINTSTAUTS = '1' and CARD_I05 is null and CARD_V05 is null ORDER BY CARD_REGISTERTIME ";

            if (SQL.GetDataSet(sql).Rows.Count > 0)
            {
                ID = Convert.ToInt32(SQL.GetDataSet(sql).Rows[0]["CARD_ID"]);
                timer1.Start();
            }
            else
            {
                timer1.Stop();
                this.notifyIcon1.Icon = ico2;
            }


        }
        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {   //获取本机IP
            string hostName = System.Net.Dns.GetHostName();   //获取本机名
            System.Net.IPHostEntry localhost = System.Net.Dns.GetHostByName(hostName);    //方法已过期，可以获取IPv4的地址
            System.Net.IPAddress localaddr = localhost.AddressList[0];
            string add = localaddr.ToString();
            //I05为 null表示未点击图标  点击后修改为 0 即正在审批中
            string sql = "update T_CARDINFO SET CARD_V05 = '"+ add+"'  WHERE CARD_ID = '"+ID+"'";
            SQL.ExecuteSql(sql);
            //双击打开地址
            string ip = System.Configuration.ConfigurationSettings.AppSettings["ipaddr"];
            System.Diagnostics.Process.Start(ip);
            

        }
    }
}
